(Al-Baqara) 2 : 271
إِنْ تُبْدُوا الصَّدَقَاتِ فَنِعِمَّا هِيَ ۖ وَإِنْ تُخْفُوهَا وَتُؤْتُوهَا الْفُقَرَاءَ فَهُوَ خَيْرٌ لَكُمْ ۚ وَيُكَفِّرُ عَنْكُمْ مِنْ سَيِّئَاتِكُمْ ۗ وَاللَّهُ بِمَا تَعْمَلُونَ خَبِيرٌ

If you are disclosing the charities, it is well; and if you are concealing them and are giving them to the poor, it is better for you, and it cancels out some of your evil deeds from you; and Lord Allah is Acquainted with whatever you are doing.

If anyone discloses his charity before the public intending to encourage others to do so, there is no blame upon him. That will be accepted per his intention. The believer, by considering the Lord as the Impartial and as the Three-Time-Knower, spends in charities secretly to the most deserving persons among mankind. Thus, he can erase the evil deeds recorded in the Recording Book fastened upon his neck as explained in verses 17: 13-14. It is told in verses 35: 29: “Those who are reading and conveying Adhikr, performing prayer, and spending secretly and openly from whatever Lord has provided them, they are expecting a trade that will never fail”. It is told in verses 39: 34-35: “The heedful and Muhsins who are testifying the Best Book Adhikr will transform themselves their evil deeds into righteous deeds”. It is told in verse 65: 5: “Those who heed the Lord, Lord will transform his evil deeds into good and increase his reward”. See explanation 2: 214; 5: 39 and 8: 29.